package com.example.moreeyes;

import android.content.Context;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link HomeFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class HomeFragment extends Fragment {
    private Context mContext;
    private static final String TAG = "HomeFragment";
    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    // TODO: Rename and change types of parameters
    private String mParam1;
    private String mParam2;

    public HomeFragment() {
        // Required empty public constructor
        Log.d(TAG,"HomeFragment INIT");
    }

    /**
     * 当Activity Created会依次调用调用Fragment的onAttach,onCreate,onCreateView,onActivitityCreated
     * Fragment的生命周期
     * @param context
     * Fragment必须是依存与Activity而存在的，Activity的生命周期会直接影响到Fragment生命周期
     */
    @Override
    public void onAttach(@NonNull Context context) {
        super.onAttach(context);
        mContext = context;
        Log.d(TAG,"HomeFragment onAttach");
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
        Log.d(TAG,"HomeFragment onCreate");
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        Log.d(TAG,"HomeFragment onCreateView");
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_home, container, false);

    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        Log.d(TAG,"HomeFragment onActivityCreated");
        super.onActivityCreated(savedInstanceState);
    }

    /**
     * 关联Activity的onStart方法
     */
    @Override
    public void onStart() {
        super.onStart();
        Log.d(TAG,"HomeFragment onStart");
    }
    /**
     * 关联Activity的onResume方法
     */
    @Override
    public void onResume() {
        super.onResume();
        Log.d(TAG,"HomeFragment onResume");
    }

    /**
     * 关联Activity的onPause方法
     */
    @Override
    public void onPause() {
        super.onPause();
        Log.d(TAG,"HomeFragment onPause");
    }

    /**
     * 关联Activity的Destroyed方法
     */
    @Override
    public void onDestroyView() {
        super.onDestroyView();
        Log.d(TAG,"HomeFragment onDestroyView");
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.d(TAG,"HomeFragment onDestroy");
    }

    @Override
    public void onDetach() {
        super.onDetach();
        Log.d(TAG,"HomeFragment onDetach");
    }

    /**
     * Use this factory method to create a new instance of
     * this fragment using the provided parameters.
     *
     * @param param1 Parameter 1.
     * @param param2 Parameter 2.
     * @return A new instance of fragment HomeFragment.
     */
    // TODO: Rename and change types and number of parameters
    public static HomeFragment newInstance(String param1, String param2) {
        Log.d(TAG,"HomeFragment newInstance");
        HomeFragment fragment = new HomeFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }
}